import pandas as pd
import tool.WindDirection as WindDirection
import tool.RainFall as RainFall
import tool.DataFill as DataFill


if __name__ == '__main__':
    # 读取文件
    print("读取文件")
    file_name = '57411(南充市)_01.01.2006_01.01.2023.csv'
    dataframe = pd.read_csv('./file/' + file_name, encoding="utf-8", na_values="NaN")

    # 数值替换(优先将文件中的str转化为float64)
    # print("替换字符串")
    # for index in range(len(dataframe)):
    #     dataframe.loc[index, "风向"] = WindDirection.get_wind_direction(dataframe.loc[index, "风向"])
    #     dataframe.loc[index, "降水量（毫米）"] = RainFall.get_rain_fall(dataframe.loc[index, "降水量（毫米）"])

    # 日期的格式修改与填充
    # print("填充日期")
    # dataframe = DataFill.date_fill(dataframe, "当地时间", "2006-01-01 02:00:00", "2023-01-01 23:00:00", "3H")

    # 复制填充(通过复制不同年份的同一天数据来处理大片缺失的情况
    print("通过分块复制填充大空白")
    # dataframe = DataFill.data_copy(dataframe, "水平大气压（毫米汞柱）", filt_len=5)
    # dataframe = DataFill.data_copy(dataframe, "海平面大气压（毫米汞柱）", filt_len=5)
    dataframe = DataFill.data_copy(dataframe, "气压变化趋势", filt_len=5)

    # 继承填充的列
    print("通过插值填充小空白")
    # dataframe = DataFill.solid_fill(dataframe, "风向")
    # dataframe = DataFill.solid_fill(dataframe, "平均风速（m/s）")
    # dataframe = DataFill.solid_fill(dataframe, "过去12小时内最低气温")
    # dataframe = DataFill.solid_fill(dataframe, "过去12小时内最高气温")
    # dataframe = DataFill.solid_fill(dataframe, "降水量（毫米）")
    # dataframe = DataFill.solid_fill(dataframe, "到达规定降水量的时间")
    # 平滑填充的列
    # dataframe = DataFill.smooth_fill(dataframe, "大气温度（摄氏度）")
    # dataframe = DataFill.smooth_fill(dataframe, "水平大气压（毫米汞柱）")
    # dataframe = DataFill.smooth_fill(dataframe, "海平面大气压（毫米汞柱）")
    # dataframe = DataFill.smooth_fill(dataframe, "气压变化趋势")
    # dataframe = DataFill.smooth_fill(dataframe, "相对湿度")
    # dataframe = DataFill.smooth_fill(dataframe, "水平能见度（km）")
    # dataframe = DataFill.smooth_fill(dataframe, "露点温度（摄氏度）")

    # 保存结果
    dataframe.to_csv('./file/products/p_' + file_name, encoding="utf-8", index=False)

